How to round currency values [migrated]
Posted
by
Kenny
on Programmers
See other posts from Programmers
or by Kenny
Published on 2011-07-01T14:03:43Z
Indexed on
2011/07/01
16:30 UTC
Read the original article
Hit count: 385
algorithms
|money
I already have several ways to solve this, but I am interested in whether there is a better solution to this problem. Please only respond with a pure numeric algorithm. String manipulation is not acceptable. I am looking for an elegant and efficient solution.
Given a currency value (ie $251.03), split the value into two half and round to two decimal places. The key is that the first half should round up and the second should round down. So the outcome in this scenario should be $125.52 and $125.51.
© Programmers or respective owner